import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css';

import popup from './components/popup/index.vue'
import top from './components/top.vue'
import sideBar from './components/sideBar.vue'

import eventBus from './utils/bus'

function setRemUnit() {
    const baseSize = 10; // 基准字体大小 (1rem = 10px)
    const designWidth = 1900; // 设计稿宽度
    const scale = document.documentElement.clientWidth / designWidth;
    document.documentElement.style.fontSize = baseSize * scale + 'px';
}

// 初始化
setRemUnit();

// 监听窗口大小变化
window.addEventListener('resize', setRemUnit);

const app = createApp(App)

const pinia = createPinia()
pinia.use( piniaPluginPersistedstate ) //添加持久化插件

// 插件
app.use(pinia)
app.use(router)
app.use(ElementPlus)
// 组件
app.component('PopupModal', popup)
app.component('Top', top)
app.component('SideBar', sideBar)

app.config.globalProperties.$eventBus = eventBus

app.mount('#app')
